<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- Author Johan Sandström-->
<ui:composition
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.prime.com.tr/ui"
    xmlns:f="http://java.sun.com/jsf/core"
    template="WEB-INF/facelets/template.xhtml">

    <ui:define name="content">
        <p:panel header="This is your shopping cart">
            <p/>
            <h:form id="cartForm">  
                <p:dataTable var="order" value="#{shoppingCartModelBean.cart}"
                             paginator="true" rows="5"
                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} 
                             {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}">  

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Quantity" />  
                        </f:facet>  
                        <h:outputText value="#{order.qty}" />  
                    </p:column> 

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Album" />  
                        </f:facet>  
                        <h:outputText value="#{order.product.name}" />  
                    </p:column> 

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Artist" />  
                        </f:facet>  
                        <h:outputText value="#{order.product.artist}" />  
                    </p:column> 
                    <p:column>  
                        <p:commandButton value="Remove one" 
                                         actionListener="#{viewCartControllerBean.removeOneProduct(order.product)}" action="removeOneProduct" update="@form"/>
                    </p:column> 
                    <p:column>  
                        <p:commandButton value="Remove all" 
                                         actionListener="#{viewCartControllerBean.removeProduct(order.product)}" action="emptyCart" update="@form"/>
                    </p:column> 
                </p:dataTable>

                <p:commandButton value="Pay" action="#{viewCartControllerBean.confirmOrder()}"></p:commandButton>

                <p:commandButton value="Empty Cart" 
                                 actionListener="#{viewCartControllerBean.emptyCart()}" action="emptyCart"/>
                <p:messages showDetail="true" showSummary="false"/>

            </h:form>  
        </p:panel>
    </ui:define>


</ui:composition>